<?php
/**
 * Created by PhpStorm.
 * User: zhang
 * Date: 2018/4/29
 * Time: 13:51
 */
namespace app\account\controller;

use app\common\model\Base;
use app\account\model\GetSMS;

class FindPassword extends Base{

    public $sms;

    public function __construct()
    {
        parent::__construct();
        $this->sms = new GetSMS();
    }

    /**
     *
     * @api {post} /account/findpassword  密码修改
     * @apiDescription 密码修改
     * @apiGroup account
     * @apiVersion 0.1.0
     * @apiParam {string} tel 电话号码
     * @apiParam {string} authCode 验证码
     * @apiParam {string} passd 密码
     *
     * @apiParamExample {json} Request-Example:
     *     {
     *       "tel": 17754928306，
     *       "passd": 123456789
     *       "authCode":"xxx"
     *     }
     * @apiError {String} code 0 表示失败
     * @apiError {String} msg  "xxx"
     *
     * @apiSuccess {String} code 1 表示成功.
     * @apiSuccess {String} msg 注册成功.
     * @apiSuccessExample {json} Success-Response:
     *     {
     *       "code": "1",
     *       "msg": "xxx"
     *     }
     */
    function index(){
        $tel = $_GET["tel"];
        $authCode = $_GET["authCode"];
        $passd = $_GET["passd"];


        if(!$this->check->isTelExists($tel,$authCode ,$passd,"FIND_PASSWORD"))
            return;

        $this->findPassd($tel,$passd);
    }

    /**
     * 修改密码
     * @param str $tel 账号
     * @param str $passd 密码
     */
    function findPassd($tel, $passd) {
        $sql = "UPDATE user SET passd='$passd' WHERE TEL='$tel'";

        if ($this->mysql->updateSQL($sql)) {
            echo echoJson(1, "密码修改成功!");
        } else {
            echo echoJson(0, "密码修改失败，请稍后再试!");
        }
    }

    /**
     *
     * @api {post} /account/findpassword/getAutoCode  密码修改获取验证码
     * @apiDescription 密码修改获取验证码
     * @apiGroup account
     * @apiVersion 0.1.0
     * @apiParam {string} tel 电话号码
     *
     * @apiError {String} code 0 表示失败
     * @apiError {String} msg  "xxxxx"
     *
     * @apiSuccess {String} code 1 表示成功.
     * @apiSuccess {String} msg 注册成功.
     */
    function getAutoCode(){
        $tel=$_GET["tel"];
        $this->sms->judgeSMSType($tel,"FIND_PASSWORD");
    }
    
}